package com.station.controller;


import com.station.service.BasicDataService;
import com.station.service.PurchaseDataService;
import com.station.service.TransferOrderDataService;
import com.station.utils.R;
import com.station.vo.ItemVo;
import com.station.vo.RelateDunitVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:基础数据模块对接
 * @Author: dongfangyu
 * @Date: 2025/9/17
 */
@Slf4j
@RequestMapping("/basicData")
@RestController
public class BasicDataController {


    @Autowired
    private BasicDataService basicDataService;
    @Autowired
    private PurchaseDataService purchaseDataService;
    @Autowired
    private TransferOrderDataService transferOrderDataService;
    /**
     * 创建供应商
     */
    @PostMapping("/createSupplier")
    public R createSupplier(@RequestBody RelateDunitVo relateDunitVo) {
        if (null == relateDunitVo) {
            return R.error("供应商数据不能为空！");
        }
        return basicDataService.createSupplier(relateDunitVo);
    }

    /**
     * 批量创建供应商
     *
     * @return
     */
    @GetMapping("/batchCreateSupplier")
    public R batchCreateSupplier() {
        return basicDataService.batchCreateSupplier();
    }

    @GetMapping("/queryList")
    public R queryList() {
        return R.ok().put("data", basicDataService.selectSupplierList());
    }


    /**
     * 创建物料
     */
    @PostMapping("/createMaterials")
    public R createMaterials(@RequestBody ItemVo itemVo) {
        if (null == itemVo) {
            return R.error("物料数据不能为空！");
        }
        R result = basicDataService.createMaterials(itemVo);
        return result;
    }

    /**
     * 批量创建物料
     */
    @GetMapping("/batchCreateMaterials")
    public R batchCreateMaterials() {
        R result = basicDataService.batchCreateMaterials();
        return result;
    }

    /**
     * 批量同步计量单位
     *
     * @return
     */
    @GetMapping("/syncMaterialsUnitList")
    public R syncMaterialsUnitList() {
        return basicDataService.batchSyncUnit();
    }

    /**
     * 批量同步销售入库单
     *
     * @return
     */
    @GetMapping("/syncInStock")
    public R syncInStock(String startDate, String endDate) {
        return purchaseDataService.batchSyncInStock(startDate,endDate);
    }

    /**
     * 批量同步采购订单
     *
     * @return
     */
    @GetMapping("/batchSyncPurchase")
    public R batchSyncPurchase(String startDate, String endDate) {
        return purchaseDataService.batchSyncPurchase(startDate,endDate,null);
    }

    /**
     * 批量同步付款单
     *
     * @return
     */
    @GetMapping("/batchSyncPayBill")
    public R batchSyncPayBill(String startDate, String endDate) {
        return purchaseDataService.batchSyncPayBill(startDate,endDate);
    }

    /**
     * 确定需要同步的有预付款的采购数据
     *
     * @return
     */
    @GetMapping("/payBillByPurchase")
    public R payBillByPurchase(String startDate, String endDate) {
        return purchaseDataService.payBillByPurchase(startDate,endDate);
    }

    /**
     * 确定需要同步的有预付款的采购数据
     *
     * @return
     */
    @GetMapping("/batchSyncTransfer")
    public R batchSyncTransfer(String startDate, String endDate) {
        return transferOrderDataService.batchSyncTransfer(startDate,endDate);
    }


    /**
     * 批量同步采购退货单
     *
     * @return
     */
    @GetMapping("/batchSyncPurchaseReturn")
    public R batchSyncPurchaseReturn(String startDate, String endDate) {
        return purchaseDataService.batchSyncPurchaseReturn(startDate,endDate);
    }

    /**
     * 批量同步采购退货单
     *
     * @return
     */
    @GetMapping("/getPurchaseOrderByNo")
    public R getPurchaseOrderByNo(String orderNo) {
        return purchaseDataService.getPurchaseOrderByNo(orderNo);
    }

}
